<template>
  <!-- // 代理账单页面  -->
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="请输入用户名或是移动号码" v-model="search.realname"></el-input>
      <el-date-picker v-model="search_time" type="daterange" range-separator="至" start-placeholder="开始日期"  end-placeholder="结束日期" class="filter-item" value-format="yyyy-MM-dd" ></el-date-picker>      
      <el-button class="filter-item" type="primary" plain icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <!-- // 这是列表 -->
    <div style="color:#999;margin-bottom:5px">*注: 默认为当月统计数据</div>
    <el-table :data="listData" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row style="width: 100%">
      <el-table-column type="index"  align="center" label="序号" width="80"></el-table-column>
      <el-table-column align="center" label="用户名称"  width="160">
        <template slot-scope="scope">
          <span>{{scope.row.realname}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="移动号码"  width="120">
        <template slot-scope="scope">
          <span>{{scope.row.mobile}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="未结单金额(元)"  width="180">
        <template slot-scope="scope">
          <span>{{scope.row.total_amount}}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="配送中" width="180">
        <template slot-scope="scope">
          <span style="color:red;font-size:16px">{{scope.row.underway}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="配送完成"  width="180">
        <template slot-scope="scope">
          <span>{{scope.row.finish}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="未完成"  width="180">
        <template slot-scope="scope">
          <span>{{scope.row.cancel}}</span>
        </template>
      </el-table-column>
      <!-- //这里是操作   -->
      <el-table-column align="center" label="操作"  width="100"  fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button  size="mini" type="primary" @click="handlLook(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--用户编辑窗口  -->
    <look-courier  :visible.sync="lookVisible"  :propsData="propsData" @refresh='isrefresh'></look-courier>  
    <!--编辑窗口  END -->

    <!--可自定义按钮的样式、show/hide临界点、返回的位置  -->
    <!--如需文字提示，可在外部添加element的<el-tooltip></el-tooltip>元素  -->
    <el-tooltip placement="top" content="回到顶部">
      <back-to-top transitionName="fade" :customStyle="myBackToTopStyle" :visibilityHeight="300" :backPosition="50"></back-to-top>
    </el-tooltip>
  </div>
</template>


<script>
import BackToTop from '@/components/BackToTop' // 回到顶部
import * as api from '@/api/main-api' // API
import lookCourier from '../orders/lookCourierProfit'
import { mapGetters } from 'vuex'

export default {
  name: 'courierProfit',

  components: { BackToTop, lookCourier },
  computed: {
    ...mapGetters([
      'outlet_id'
    ])
  },
  data() {
    return {
      // 回到顶部样式
      myBackToTopStyle: {
        right: '50px',
        bottom: '50px',
        width: '40px',
        height: '40px',
        'border-radius': '4px',
        'line-height': '45px', // 请保持与高度一致以垂直居中 Please keep consistent with height to center vertically
        background: '#e7eaf1'// 按钮的背景颜色 The background color of the button
      },

      listQuery: {
        unit_id: 0
      },

      // 搜索字段
      search: {
        realname: ''
      },
      search_time: [],
      listLoading: false,
      listData: [],
      // 编辑传值
      lookVisible: false,
      propsData: {}
    }
  },

  // 初始化数据
  created() {
    this.listQuery.unit_id = this.outlet_id
    setTimeout(() => {
      this.fetchData()
    }, 20)
  },

  // 触动方法
  methods: {

    // 查看按钮
    handlLook(row) {
      this.lookVisible = !this.lookVisible
      this.propsData = row
      // 传入父页面的数据
      if (this.search_time) {
        this.propsData.stime = this.search_time[0]
        this.propsData.etime = this.search_time[1]
      }
    },

    // 子窗口关闭,刷新数据
    isrefresh(data) {
      this.fetchData()
    },

    // 搜搜
    handleFilter() {
      if (this.search_time) {
        this.search.stime = this.search_time[0]
        this.search.etime = this.search_time[1]
      }
      // 复制一个对象<br>var obj = { a: 1 ,b:2};
      this.listQuery = Object.assign(this.listQuery, this.search)
      this.fetchData()
    },

    // 获取数据
    fetchData() {
      this.listLoading = true
      api.courierReportApi(this.listQuery).then(response => {
        if (response.data.code === 0) {
          this.listData = response.data.data
        }
        this.listLoading = false
      })
    }

  },
  // 监事事件
  watch: {
    outlet_id(id) {
      this.$nextTick(() => {
        setTimeout(() => {
          this.listQuery.unit_id = id
          this.fetchData()
        }, 20)
      })
    }
  }
}
</script>
